package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Person;
import com.ruoyi.system.service.IPersonService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 企业主股东主要成员 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-04-26
 */
@Controller
@RequestMapping("/system/person")
public class PersonController extends BaseController
{
    private String prefix = "system/person";
	
	@Autowired
	private IPersonService personService;
	
	@RequiresPermissions("system:person:view")
	@GetMapping()
	public String person()
	{
	    return prefix + "/person";
	}
	
	/**
	 * 查询企业主股东主要成员列表
	 */
	@RequiresPermissions("system:person:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Person person)
	{
		startPage();
        List<Person> list = personService.selectPersonList(person);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出企业主股东主要成员列表
	 */
	@RequiresPermissions("system:person:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Person person)
    {
    	List<Person> list = personService.selectPersonList(person);
        ExcelUtil<Person> util = new ExcelUtil<Person>(Person.class);
        return util.exportExcel(list, "person");
    }
	
	/**
	 * 新增企业主股东主要成员
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存企业主股东主要成员
	 */
	@RequiresPermissions("system:person:add")
	@Log(title = "企业主股东主要成员", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Person person)
	{		
		return toAjax(personService.insertPerson(person));
	}

	/**
	 * 修改企业主股东主要成员
	 */
	@GetMapping("/edit/{pid}")
	public String edit(@PathVariable("pid") Integer pid, ModelMap mmap)
	{
		Person person = personService.selectPersonById(pid);
		mmap.put("person", person);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存企业主股东主要成员
	 */
	@RequiresPermissions("system:person:edit")
	@Log(title = "企业主股东主要成员", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Person person)
	{		
		return toAjax(personService.updatePerson(person));
	}
	
	/**
	 * 删除企业主股东主要成员
	 */
	@RequiresPermissions("system:person:remove")
	@Log(title = "企业主股东主要成员", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(personService.deletePersonByIds(ids));
	}
	
}
